<template>
  <div class="JournalListCom">
    <jxtech-page-table ref="JournalListTableRef" row-key="ruleCode" fit="full" :table-column="JournalListComState.tableColumn"
                       :load-data="JournalListComState.loadData" :exp-data="JournalListComState.expData"
                       @selection-change="JournalListComState.tableSelectionChange">
      <template #header>
        <div class="jxtech-page-table-header-flex">
          <jxtech-search-form :query-column="JournalListComState.queryColumn" :query-form="JournalListComState.queryParam" :col-span="6"
                              @handle-search="JournalListComState.handleSearch">

          </jxtech-search-form>
        </div>
      </template>

      <!-- <template #actionSlot="{ row }">
        <el-button type="" @click="JournalListComState.detailhandler(row)">
          <jxtech-svg-icon icon="#icon-detail" class="pointer"></jxtech-svg-icon>&nbsp;详 情
        </el-button>
        <el-divider direction="vertical"></el-divider>
        <el-button type="danger" @click="JournalListComState.deletehandler(row)">
          <jxtech-svg-icon icon="#icon-delete" class="pointer"></jxtech-svg-icon>&nbsp;删 除
        </el-button>
      </template> -->

    </jxtech-page-table>
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref, onMounted } from "vue"
import journalServiceApi from "/@/api/personnel/bean/journal"
import { ElNotification, ElMessageBox, ElMessage } from "element-plus"
import { InspectDetailUrl } from "/@/views/personnel/mapping.json"
import { useRouter } from "vue-router"
const JournalListTableRef = ref()
const JournalListComState = reactive({
  handleSearch: () => JournalListTableRef.value.loadTable(),
  queryColumn: [
    {
      name: "applyNo",
      type: "input",
      label: "请求流水号",
      placeholder: "请求流水号"
    }
  ],
  queryParam: { likeAll: null },
  selectionData: [] as any[],
  tableColumn: [
    // { label: "序号", width: "50", type: "selection" },
    { label: "序号", width: "50", type: "index" },
    { prop: "applyNo", label: "请求流水号" },
    { prop: "name", label: "接口名称" },
    { prop: "ip", label: "客户端IP" },
    { prop: "systemid", label: "所属系统" },
    { prop: "applyPerson", label: "接口描述" },
    { prop: "token", label: "返回token" },
    { prop: "applyDate", label: "请求时间" }
    // { label: "操作", slot: "actionSlot", width: "200" }
  ],
  //表格数据加载的方法
  loadData: (params: any) => {
    return journalServiceApi.queryPage(
      { refCols: "default" },
      {
        ...params,
        ...JournalListComState.queryParam
      }
    )
  },
  expData: (params: any) => {
    // return rulelibraryServiceApi.exportData(null, {
    //   ...params,
    //   ...JournalListComState.queryParam
    // })
  },
  tableSelectionChange: (dataList: any[]) => {
    JournalListComState.selectionData = dataList
  },
  deletehandler: (row: any) => {
    ElMessageBox.confirm("您确定要删除选择的数据么?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    })
      .then(() => {
        journalServiceApi.delete(row.ruleCode, null).then(response => {
          ElNotification({
            title: "删除成功",
            message: "规则编码-" + row.ruleCode,
            type: "success"
          })
          JournalListTableRef.value.loadTable()
        })
      })
      .catch(() => {
        // ElMessage({
        //   type: 'info',
        //   message: 'Delete canceled',
        // })
      })
  },
  detailhandler: (row: any) => {
    router.push({ path: InspectDetailUrl, query: { ruleCode: row.ruleCode } })
  },
  multideletehandler: () => {
    if (!JournalListComState.selectionData.length) {
      return ElNotification({
        title: "错误",
        message: "没有选择任何数据",
        type: "error"
      })
    }
    ElMessageBox.confirm("您确定要删除选择的数据么?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    })
      .then(() => {
        const idsarray: string[] = []
        JournalListComState.selectionData.forEach(item => {
          idsarray.push(item.ruleCode)
        })
        journalServiceApi.saveMultiDelete(idsarray, null).then(response => {
          ElNotification({
            title: "删除成功",
            message: "ruleCode-" + idsarray,
            type: "success"
          })
          JournalListTableRef.value.loadTable()
        })
      })
      .catch(() => {
        // ElMessage({
        //   type: 'info',
        //   message: 'Delete canceled',
        // })
      })
  }
})
onMounted(() => {
  JournalListTableRef.value.loadTable()
})
</script>

<style lang="scss" scoped>
</style>
